]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
brightnessManager: Make the steps of a BrightnessScale variable
authorSebastian Wick <sebastian.wick@redhat.com>
Tue, 5 Aug 2025 08:32:39 +0000 (10:32 +0200)
committerMarge Bot <marge-bot@gnome.org>
Thu, 7 Aug 2025 21:57:54 +0000 (21:57 +0000)
This allows each brightness scale to use different number of steps when
using stepUp/stepDown. We will use this in the following commits to
better deal with backlights which have a limited amount of discrete
steps.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3826>

js/misc/brightnessManager.js

index 082487a64847e10319b4eb7a19731460ea2d5934..b9d3a540f8a0d812c30ed2144e6883ad17b2ed35 100644 (file)
@@ -5,7 +5,7 @@ import Shell from 'gi://Shell';
 
 import * as Main from '../ui/main.js';
 
-const SCALE_VALUE_STEP = 0.1;
+const SCALE_VALUE_N_STEPS = 10;
 const SCALE_VALUE_CHANGE_EPSILON = 0.001;
 
 const KEYBINDING_SCHEMA = 'org.gnome.shell.keybindings';
@@ -273,12 +273,13 @@ export const BrightnessScale = GObject.registerClass({
             false),
     },
 }, class BrightnessScale extends GObject.Object {
-    constructor(name, value = 1.0) {
+    constructor(name, value = 1.0, nSteps = SCALE_VALUE_N_STEPS) {
         super();
 
         this._name = name;
         this._value = value;
         this._locked = false;
+        this._nSteps = nSteps;
     }
 
     get name() {
@@ -304,12 +305,16 @@ export const BrightnessScale = GObject.registerClass({
         this.notify('locked');
     }
 
+    get nSteps() {
+        return this._nSteps;
+    }
+
     stepUp() {
-        this._setValue(Math.min(1.0, this._value + SCALE_VALUE_STEP));
+        this._setValue(Math.min(1.0, this._value + (1.0 / this._nSteps)));
     }
 
     stepDown() {
-        this._setValue(Math.max(0.0, this._value - SCALE_VALUE_STEP));
+        this._setValue(Math.max(0.0, this._value - (1.0 / this._nSteps)));
     }
 
     cycleUp() {